<?php
$server = new swoole_server("127.0.0.1", 9501);
$server->set(array(
    'worker_num'      => 2,
    'task_worker_num' => 3,
));
$server->on('Receive', function (Swoole\Server $server, $fd, $reactor_id, $data) {
    echo "接收数据" . $data . "\n";
    $data    = trim($data);
    $task_id = $server->taskwait($data,1);
    var_dump($task_id);
    echo "====登录成功===".PHP_EOL;
});

$server->on('Task', function (Swoole\Server $server, $task_id, $reactor_id, $data) {
    sleep(0.5);
    echo "Tasker进程接收到数据".PHP_EOL;
    $server->finish($data);
});

$server->on('Finish', function (Swoole\Server $server, $task_id, $data) {
    echo "Task#$task_id finished, data_len=" . strlen($data) . PHP_EOL;
});

$server->on('workerStart', function ($server, $worker_id) {
    global $argv;
    if ($worker_id >= $server->setting['worker_num']) {
        swoole_set_process_name("php {$argv[0]}: task_worker");
    } else {
        swoole_set_process_name("php {$argv[0]}: worker");
    }
});

$server->start();